<%--
  Created by IntelliJ IDEA.
  User: 熊自国
  Date: 2024/11/21
  Time: 11:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-L-admin1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/static/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/xadmin.css">
    <script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/layui/layui.js"
            charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        a.disabled {
            color: black; /* 禁用后链接颜色变为黑色 */
            pointer-events: none; /* 禁止鼠标事件 */
            cursor: default; /* 改变鼠标指针样式为默认 */
            opacity: 0.5; /* 可选：降低透明度以指示链接已禁用 */
        }

        #myButton {
            position: absolute;
            right: 0; /* 将按钮定位到右边 */
            /*top: 50%; !* 可选：垂直居中，需要配合transform属性 *!*/
            /*transform: translateY(-50%); !* 可选：垂直居中 *!*/
        }
    </style>
</head>

<body class="layui-anim layui-anim-up">
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
    <a class="layui-btn layui-btn-primary layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:38px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form id="f1" class="layui-form layui-col-md12 x-so" action="${pageContext.request.contextPath}/pur/findPurchase.do"
              method="get">
            <input class="layui-input" placeholder="开始日" name="start" id="start" value="${start}">
            <input class="layui-input" placeholder="截止日" name="end" id="end" value="${end}">
            <input type="hidden" name="pageNum" id="pageNum">
            <input type="hidden" name="pageSize" id="pageSize">
            <input type="text" name="purchaseOrder" placeholder="请输入订单号" autocomplete="off" class="layui-input"
                   value="${purchaseOrder}">
            <button class="layui-btn" type="submit" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i>
            </button>
            <button class="layui-btn layui-btn-normal" id="myButton" type="button"
                    onclick="x_admin_show('添加采购订单表','${pageContext.request.contextPath}/pur/findSupplier.do',1000,500)">
                添加
            </button>
        </form>
    </div>
    <div class="layui-row">
        <form id="f2" class="layui-form layui-col-md12 x-so"
              action="${pageContext.request.contextPath}/pur/statusPur.do" method="get">
            <input type="hidden" name="purchaseId" id="purchaseId">
            <input type="hidden" name="status" id="status">

        </form>
    </div>
    <%--    <div class="layui-row">--%>
    <%--        <form  id="f3" class="layui-form layui-col-md12 x-so" action="${pageContext.request.contextPath}/sale/statusSaleMin.do" method="get">--%>
    <%--            <input type="hidden" name="warehouseProductsId" id="wa">--%>
    <%--        </form>--%>
    <%--    </div>--%>
    <xblock>
        <%--        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>--%>
        <%--        <button class="layui-btn" onclick="x_admin_show('添加用户','./member-add.html',600,400)"><i class="layui-icon"></i>添加</button>--%>
        <span class="x-right" style="line-height:40px">共有数据：${purPage.total} 条</span>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i
                        class="layui-icon">&#xe605;</i></div>
            </th>
            <th>采购id</th>
            <th>采购订单号</th>
            <th>供应商名称</th>
            <th>联系人名称</th>
            <th>联系电话</th>
            <th>购买数量</th>
            <th>总计花费</th>
            <th>真实姓名</th>
            <th>状态</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach var="sale" items="${purPage.list}">
            <tr>
                <td>
                    <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='${sale.purchaseId}'><i
                            class="layui-icon">&#xe605;</i></div>
                </td>
                <td>${sale.purchaseId}</td>
                <td>${sale.purchaseOrder}</td>
                <td>${sale.supplierName}</td>
                <td>${sale.contactName}</td>
                <td>${sale.phone}</td>
                <td>${sale.purchaseQuantity}</td>
                <td>${sale.total}</td>
                <td>${sale.userFullname}</td>

                <td>
                    <c:if test="${sale.status eq 0}">
                        待处理
                    </c:if>
                    <c:if test="${sale.status eq 1}">
                        已付款
                    </c:if>
                    <c:if test="${sale.status eq 2}">
                        已收货
                    </c:if>
                </td>
                <td>
                    <fmt:formatDate value="${sale.orderDate}" pattern="yyyy-MM-dd"></fmt:formatDate>
                </td>
                <td class="td-manage">
                    <a onclick="sm(${sale.purchaseId},${sale.status})" class="layui-btn layui-btn-sm layui-btn-primary"
                       style="background-color: yellow" id="a" title="启用">
                        付款
                    </a>
                    <button type="button" class="layui-btn layui-btn-warm" onclick="caigou(${sale.purchaseId},${sale.materialId})" >生成采购订单明细表</button>
                    <button class="layui-btn" onclick="x_admin('修改采购订单表','${pageContext.request.contextPath}/pur/update.do?purchaseId='+${sale.purchaseId},1000,500,${sale.status})">编辑</button>
                    <button class="layui-btn layui-btn-danger" type="button" onclick="del(${sale.status},${sale.purchaseId})">删除</button>
                </td>


                    <%--        <tr>--%>
                    <%--            <td>--%>
                    <%--                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>--%>
                    <%--            </td>--%>
                    <%--            <td>1</td>--%>
                    <%--            <td>小明</td>--%>
                    <%--            <td>男</td>--%>
                    <%--            <td>13000000000</td>--%>
                    <%--            <td>admin@mail.com</td>--%>
                    <%--            <td>北京市 海淀区</td>--%>
                    <%--            <td>2017-01-01 11:11:42</td>--%>
                    <%--            <td class="td-status">--%>
                    <%--                <span class="layui-btn layui-btn-normal layui-btn-sm">已启用</span></td>--%>
                    <%--            <td class="td-manage">--%>
                    <%--&lt;%&ndash;                href="javascript:mm('${sale.purchaseId},${sale.status}')"&ndash;%&gt;--%>
                    <%--                <a  onclick="sm(${sale.purchaseId},${sale.status})" class="layui-btn layui-btn-sm layui-btn-primary" style="background-color: yellow" id="a"    title="启用">--%>
                    <%--                    付款--%>
                    <%--                </a>--%>
                    <%--                <a title="编辑" class="layui-btn layui-btn-sm layui-btn-normal"  onclick="x_admin_show('编辑','member-edit.html',600,400)" href="javascript:;">--%>
                    <%--                    编辑--%>
                    <%--                </a>--%>
                    <%--                <a  class="layui-btn layui-btn-sm layui-btn-warm" onclick="x_admin_show('修改密码','member-password.html',600,400)" title="修改密码" href="javascript:;">--%>
                    <%--                    修改密码--%>
                    <%--                </a>--%>
                    <%--                <a title="删除" class="layui-btn layui-btn-sm layui-btn-danger" onclick="member_del(this,'要删除的id')" href="javascript:;">--%>
                    <%--                    删除--%>
                    <%--                </a>--%>
                    <%--            </td>--%>
                    <%--        </tr>--%>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <div class="page">
        <div>
            当前第${purPage.pageNum}/总共${purPage.pages} 页
            <c:if test="${purPage.hasPreviousPage}">
                <a class="prev" href="javascript:go('${purPage.prePage}')">&lt;&lt;</a>
            </c:if>
            <c:choose>
                <c:when test="${purPage.pages<=10}">
                    <c:set var="begin" value="1"></c:set>
                    <c:set var="end" value="${purPage.pages}"></c:set>
                </c:when>
                <c:otherwise>
                    <c:set var="begin" value="${purPage.pageNum-5}"></c:set>
                    <c:set var="end" value="${purPage.pageNum+4}"></c:set>
                    <c:if test="${begin<1}">
                        <c:set var="begin" value="1"></c:set>
                        <c:set var="end" value="10"></c:set>
                    </c:if>
                    <c:if test="${end>purPage.pages}">
                        <c:set var="begin" value="${purPage.pages-9}"></c:set>
                        <c:set var="end" value="${purPage.pages}"></c:set>
                    </c:if>
                </c:otherwise>
            </c:choose>
            <c:forEach var="i" begin="${begin}" end="${end}">
                <c:choose>
                    <c:when test="${purPage.pageNum eq i}">
                        <span class="current">${i}</span>
                    </c:when>
                    <c:otherwise>
                        <a class="num" href="javascript:go(${i})">${i}</a>
                    </c:otherwise>
                </c:choose>
            </c:forEach>
            <%--            --%>
            <%--            <a class="num" href="">3</a>--%>
            <%--            <a class="num" href="">489</a>--%>
            <c:if test="${purPage.hasNextPage}">
                <a class="next" href="javascript:go('${purPage.nextPage}')">&gt;&gt;</a>
            </c:if>

        </div>
    </div>

</div>
<script>
    // $(document).ready(function() {
    //    var yuzhi =$("#yuzhi").value
    //     console.log(yuzhi)
    // });

    <%--$("#cai").click(function () {--%>
<%--       --%>
//    })

    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });
    function caigou(purchaseId,materialId){
       <%--window.location.href="${pageContext.request.contextPath}/pur/addCaiGou.do?purchaseId="+purchaseId+"&materialId="+materialId;--%>
        $.get("${pageContext.request.contextPath}/pur/addCaiGou.do",{purchaseId:purchaseId,materialId:materialId},function (data) {
             if(data=="ok"){
                 alert('已生成，请查看')
             }else {
                 alert('采购订单明细表已经生成')
             }
        })
    }

    /*用户-停用*/
    // function member_stop(obj,id){
    //
    //     layer.confirm('确认要下架吗？',function(index){
    //
    //         if($(obj).attr('title')=='上架'){
    //
    //             //发异步把用户状态进行更改
    //             $(obj).attr('title','下架')
    //             $(obj).find('i').html('&#xe62f;');
    //             $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已下架');
    //             layer.msg('已下架!',{icon: 5,time:1000});
    //         }else{
    //             $(obj).attr('title','上架')
    //             $(obj).find('i').html('&#xe601;');
    //
    //             $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已上架');
    //             layer.msg('已上架!',{icon: 5,time:1000});
    //         }
    //
    //     });
    // }
    //
    // function member_start(obj,id){
    //     layer.confirm('确认要上架吗？',function(index){
    //
    //         if($(obj).attr('title')=='下架'){
    //
    //             //发异步把用户状态进行更改
    //             $(obj).attr('title','上架')
    //             $(obj).find('i').html('&#xe62f;');
    //
    //             $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已上架');
    //             layer.msg('已上架!',{icon: 5,time:1000});
    //
    //         }else{
    //             $(obj).attr('title','下架')
    //             $(obj).find('i').html('&#xe601;');
    //
    //             $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已下架');
    //             layer.msg('已下架!',{icon: 5,time:1000});
    //         }
    //
    //     });
    // }
    function x_admin(title,url,w,h,status){
        if(status==1){
            alert("不能修改已支付的订单")
        }else {
            if (title == null || title == '') {
                title=false;
            };
            if (url == null || url == '') {
                url="404.html";
            };
            if (w == null || w == '') {
                w=($(window).width()*0.9);
            };
            if (h == null || h == '') {
                h=($(window).height() - 50);
            };

            layer.open({
                type: 2,
                area: [w+'px', h +'px'],
                fix: false, //不固定
                maxmin: true,
                shadeClose: true,
                shade:0.4,
                title: title,
                content: url
            });
        }

    }
    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            //发异步删除数据
            $(obj).parents("tr").remove();
            layer.msg('已删除!', {icon: 1, time: 1000});
        });
    }

    function del(status,purchaseId){
        if(status==1){
            alert("已付款的订单不能删除")
        }else {
           if(confirm("确认要删除此订单吗")){
               $.get("${pageContext.request.contextPath}/pur/delPurchase.do",{purchaseId:purchaseId},function (data){
                   if(data=="ok"){
                       alert('删除成功')
                       window.location.href="${pageContext.request.contextPath}/pur/findPurchase.do"
                   }else {
                       alert('删除失败')
                   }
               })
           }else {
               alert('已取消')
           }
        }
    }

    // function delAll (argument) {
    //
    //     var data = tableCheck.getData();
    //     console.log(data)
    //
    //     layer.confirm('确认要删除吗？'+data,function(index){
    //         //捉到所有被选中的，发异步进行删除
    //         layer.msg('删除成功', {icon: 1});
    //         $(".layui-form-checked").not('.header').parents('tr').remove();
    //     });
    // }
    function delAll(argument) {
        var data = tableCheck.getData();
        console.log(data)
        var ids = ''
        for (var i = 0; i < data.length; i++) {
            ids += data[i] + '-'
        }
        console.log(ids)
        if (data.length > 0) {
            // layer.confirm('确定要删除吗？')
            //
            //
            //  layer.msg('删除成功', {icon: 1});
            layer.confirm('确认要删除吗？' + data, function (index) {
                window.location.href = "${pageContext.request.contextPath}/sale/delSale.do?ids=" + ids;
                layer.msg('删除成功', {icon: 1});
            });
        } else {
            layer.confirm('必须选择一个')
        }

    }

    function go(pageNum) {
        $("#pageNum").val(pageNum)

        $("#f1").submit();
    }

    function sm(id, status) {
        $("#purchaseId").val(id);
        var flag = true
        if (flag) {
            if (status === 0) {
                if (confirm("确定要付款吗？")) {
                    layer.msg('已付款!', {icon: 5});
                    $("#f2").submit();
                } else {
                    alert("已取消");
                }
            } else {
                alert('已付款')
            }
        }
    }


    // function  sm(id){
    //     $("#wa").val(id)
    //     if(confirm("确定要下架吗？")){
    //         layer.msg('已下架!',{icon: 5});
    //         $("#f3").submit();
    //     }else {
    //         alert("已取消");
    //     }
    // }
</script>
</body>

</html>